package com.xiao.live.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xiao.live.entity.LiveActicityEntity;
import com.xiao.live.service.LiveActicityService;
import com.xiao.group.common.utils.PageUtils;
import com.xiao.group.common.utils.R;



/**
 * 直播的活动表
 *
 * @author 韩国涛
 * @email 2845009006@gmail.com
 * @date 2021-09-24 19:04:06
 */
@RestController
@RequestMapping("live/liveacticity")
public class LiveActicityController {
    @Autowired
    private LiveActicityService liveActicityService;



    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = liveActicityService.queryPage(params);

        return R.ok().put("page", page);
    }
    @RequestMapping("/tolist")
    public R tolist(){
        return R.ok().put("data",liveActicityService.list() );
    }
    @RequestMapping("/tokaibo")
    public R tokaibo(@RequestParam("liveId")Integer liveId){
        return liveActicityService.tokaibo(liveId);
    }

    /**
     * 查询可以上架的商品
     */

    @RequestMapping("tolivelist")
    public R toliveList(@RequestParam("liveId")Integer liveId){
        return liveActicityService.toliveLists(liveId);
    }


    /**
     * 直播商品的添加
     * @param liveId
     * @param goodsId
     * @return
     */
    @RequestMapping("toaddlist")
    public R toaddlist(@RequestParam("liveId")Integer liveId,
                       @RequestParam("goodsId")Integer goodsId){
        return liveActicityService.toaddlist(liveId,goodsId);
    }

    /**
     * 下架商品
     * @param liveId
     * @param goodsId
     * @return
     */
    @RequestMapping("toxia")
    public R toxia(@RequestParam("liveId")Integer liveId,
                       @RequestParam("goodsId")Integer goodsId){
        return liveActicityService.toxia(liveId,goodsId);
    }
    /**
     * 直播中的商品列表
     */
    @RequestMapping("togoodslist")
    public R togoodsList(@RequestParam("liveId")Integer liveId){
        return liveActicityService.togoodsList(liveId);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{liveId}")
    public R info(@PathVariable("liveId") Integer liveId){
		LiveActicityEntity liveActicity = liveActicityService.getById(liveId);

        return R.ok().put("liveActicity", liveActicity);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody LiveActicityEntity liveActicity){
		return liveActicityService.tosave(liveActicity);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody LiveActicityEntity liveActicity){
		liveActicityService.updateById(liveActicity);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] liveIds){
		liveActicityService.removeByIds(Arrays.asList(liveIds));

        return R.ok();
    }

}
